package com.example.mobile2121606109ycg0511homework;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText edtTxtMainUserName;
    private EditText edtTxtMainPassword;
    private EditText edtTxtMainPepPassword;
    private EditText edtTxtMainPhone;
    private EditText edtTxtMainMail;
    private EditText edtTxtMainYears;
    private Button btnMainRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        btnMainRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int password= Integer.parseInt(edtTxtMainPassword.getText().toString());
                int pepPassword= Integer.parseInt(edtTxtMainPepPassword.getText().toString());
                if (password == pepPassword){
                    Intent intent = new Intent(MainActivity.this,user_date_activity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("userName",edtTxtMainUserName.getText().toString().trim());
                    bundle.putString("phone",edtTxtMainPhone.getText().toString().trim());
                    bundle.putString("mail",edtTxtMainMail.getText().toString().trim());
                    bundle.putString("years",edtTxtMainYears.getText().toString().trim());
                    intent.putExtras(bundle);
                    startActivity(intent);
                }else {
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("提示")
                            .setMessage("输入的两次密码不一致")
                            .setNegativeButton("确定",new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) { }})
                            .create()
                            .show();
                }
            }
        });
    }

    private void initView() {
        edtTxtMainUserName = (EditText) findViewById(R.id.edtTxtMainUserName);
        edtTxtMainPassword = (EditText) findViewById(R.id.edtTxtMainPassword);
        edtTxtMainPepPassword = (EditText) findViewById(R.id.edtTxtMainPepPassword);
        edtTxtMainPhone = (EditText) findViewById(R.id.edtTxtMainPhone);
        edtTxtMainMail = (EditText) findViewById(R.id.edtTxtMainMail);
        edtTxtMainYears = (EditText) findViewById(R.id.edtTxtMainYears);
        btnMainRegister = (Button) findViewById(R.id.btnMainRegister);
    }
}